<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<%@page import="shmged.com.shlcm.utils.CmCreateUtil"%>
<%@page import="shmged.com.shlcm.reimbursement.CmCreateReimbursementEntry"%><html >
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="wt.httpgw.URLFactory"%>
<%@include file = "/shmged/jsp/com/shlcm/portal/main/head.jsp" %>
<head>  
    <meta charset="UTF-8">  
    <title>创建公共费用报销</title>  
    <link rel="stylesheet" type="text/css" href="<%=baseUrl %>shmged/javascript/util/jquery-easyui-1.3.3/themes/default/easyui.css">  
    <link rel="stylesheet" type="text/css" href="<%=baseUrl %>shmged/javascript/util/jquery-easyui-1.3.3/themes/icon.css">  
    <script type="text/javascript">var pageBaseUrl = "<%=baseUrl%>";</script>
    <script type="text/javascript" src="<%=baseUrl %>shmged/javascript/util/jquery-easyui-1.3.3/jquery-1.7.2.min.js"></script>  
    <script type="text/javascript" src="<%=baseUrl %>shmged/javascript/util/jquery-easyui-1.3.3/jquery.easyui.min.js"></script>  
    <script type="text/javascript" src="<%=baseUrl %>shmged/jsp/com/shlcm/portal/js/main.js"></script>  
    <style type="text/css">
        a:link {text-decoration: none;}
		a:visited {text-decoration: none;}
		a:active {text-decoration: none;}
		a:hover {text-decoration: none;}
		
		.current a {
            font-size: 20px;
        }
        .over {
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: #f5f5f5;
            opacity:0.5;
            z-index: 1000;
        }
        .layout {
            display: none;
            position: absolute;
            top: 40%;
            left: 40%;
            width: 20%;
            height: 20%;
            z-index: 1001;
            text-align:center;
        }
    </style>
</head> 
<body>
<%
	Calendar cal = Calendar.getInstance(); 
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
	String cdate = sdf.format(cal.getTime()); 
	String year=cdate.substring(0,cdate.indexOf("-"));
	String[] types=CmCreateUtil.getReimbursementType();
	String[] detailTypes=CmCreateUtil.getDetailType();
	
%>
<div align="center">
<div style="margin:10px 0;"></div>
	<div  iconCls="icon-kms-related" title="创建费用报销" style="width:700px; height: 600px; padding: 5px;" id="browseCreateReimbursement" name="browseCreateReimbursement" >
		<center>
		<form method="post" enctype="multipart/form-data" name="createRBForm" id="createRBForm">
	 <div id="p" class="easyui-panel" title="报销单" align="center">		
		<table  width="600px">
			<tr>
				<td align="right" style="width: 100px">发票数:</td>
				<td align="left"><input  type="text"  id="create_InvoiceNum"  name="create_InvoiceNum" class="easyui-numberbox" required></input></td>
				<td align="right" style="width: 100px">报销日期:</td>
				<td align="left"><input  id="create_Time"  name="create_Time"     value="<%=cdate %>"  class="easyui-datebox" data-options="formatter:myformatter,parser:myparser"></input></td>
			</tr>
			
			<tr>
				
				<td align="right">报销金额(小写):</td>
				<td align="left"><input type="text"  disabled    id="add_Sum" name="add_Sum"></input><input type="hidden" id="create_Sum" name="create_Sum"></input></td>
				<td align="right">报销金额(大写):</td>
				<td align="left"><input type="text" disabled  id="add_create_Amount" name="add_create_Amount"></input>
					<input type="hidden"  id="create_Amount" name="create_Amount"></input>
				</td>
			</tr>
			<tr>
				<td align="right">单据类型:</td>
				<td align="left">公共费用<input type="hidden" id="create_RefeBursementType" value="公共费用"  name="create_RefeBursementType">
				</input>
				
				</td>
				<td align="right">付款方式:</td>
				<td align="left"><select id="create_PayMethod" name="create_PayMethod">
						<option value="现金">现金</option>
						<option value="银行转账">银行转账</option>
					</select>
				</td>
			</tr>	
			
		</table>
		</div>
		<div style="margin:10px 0;"></div>
		<div id="p" class="easyui-panel" title="费用明细" align="center"  >
		<table width="600px">
			<tr>
    			<td align="right" style="width: 100px">费用类型:</td>
    			<td align="left">
    				<select id="detailType">
    					
    					<%
    						for(int i=0;i<detailTypes.length;i++)
    						{
    							%>
    							<option value="<%=detailTypes[i] %>"><%=detailTypes[i] %></option>
    							<% 
    						}
    					%>
    				</select>
    			</td>
    			<td align="right" style="width: 100px">金额:</td>
    			<td align="left"><input id="detaiSum" name="detaiSum" class="easyui-numberbox" required ></input></td>
    		</tr>
    		<tr>
    			<td align="right">用途:</td>
    			<td align="left"><input type="text" id="detaiTo" class="easyui-validatebox" data-options="required:true" ></input></td>
    			<td align="right">时间:</td>
    			<td align="left"><input type="text" id="detaiTime" name="detaiTime" class="easyui-datebox"  value="<%=cdate %>" data-options="formatter:myformatter,parser:myparser"></input></td>
    		</tr>
			<tr>
				<td align="right">备注:</td>
				<td colspan="2" align="left"><input type="text" id="detaiDesc"></input></td>
				<td><input type="button" onclick="appendRBDetail()" value="增加明细"></input></td>
			</tr>
		</table>
		
		 	<table id="detailTable" class="easyui-datagrid" title="费用明细" style="width:480px;height:280px"
						data-options="rownumbers:true,singleSelect:true,toolbar:'#detailButton',onClickRow: onClickRow">
						<thead>
							<tr>
							<th data-options="field:'type',width:60,align:'center'">费用类型</th>
							<th data-options="field:'amount',width:60,align:'center'">金额</th>
							<th data-options="field:'to',width:60,align:'center'">用途</th>
							<th data-options="field:'time',width:60,align:'center'">时间</th>
							<th data-options="field:'desc',width:160,align:'center'">备注</th>
							</tr>
						</thead>
					</table>
					
		<div id="detailButton" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeDetail()">删除</a>
		</div>
		
		
	</div>
	<table>
			<tr>
    			<td  align="right">
    			<input  type="hidden" id="create_RefeBursementLife" value="<%=year %>年" name="create_RefeBursementLife"></input>
    				<a href="javascript:void(0)"  id="addDetailed" onclick="addDetailed('detailed')">附件</a>
    			</td>
    			<td colspan="3" align="left"><div><input type='file' size=40 name='appendixFile"' id="appendixFile" /></div></td>
    		</tr>
		</table>
	<div style="height: 10px;"></div>
	</div>		
	<table>
		<tr>
			<td colspan="2">
      			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitCreateRBForm()">保存</a>
   			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeCreateRB()">关闭</a>
			</td>
		</tr>
	</table>
	</form>
		</center>
		
</div>
</div>
<div id="over" class="over"></div>
  <div id="layout" class="layout"><img src="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/loading.gif" /></div>
<script type="text/javascript">

function showLoading()
{
    document.getElementById("over").style.display = "block";
    document.getElementById("layout").style.display = "block";
}


var editIndex = undefined;

	function appendRBDetail()
	{
		var detailType = document.getElementById("detailType");
		detailType=detailType.options[detailType.selectedIndex].value;
		var detaiSum=$("#detaiSum").val();
		var detaiTo=$("#detaiTo").val();

		var detaiTime="";
		var begin=document.getElementsByName("detaiTime");
		for(var i=0;i<begin.length;i++)
		{
			if(begin[i].value!="")
			{
				detaiTime=begin[i].value;
			}
			
		}
		var detaidesc=$("#detaiDesc").val();
		
		if(detaiSum==null||detaiSum=="")
		{
			$.messager.alert('提示',"明细金额不能为空");
			return;
		}

		if(detaiTo==null||detaiTo=="")
		{
			$.messager.alert('提示',"明细用途不能为空");
			return;
		}

		if(detaiTime==null||detaiTime=="")
		{
			$.messager.alert('提示',"明细时间不能为空");
			return;
		}
	
		$('#detailTable').datagrid('appendRow',{type:detailType,amount:detaiSum,to:detaiTo,time:detaiTime,desc:detaidesc});
		editIndex = $('#detailTable').datagrid('getRows').length-1;
		$('#detailTable').datagrid('selectRow', editIndex)
						.datagrid('beginEdit', editIndex);
		setSum();
	}

	
	function submitCreateRBForm()
	{
		showLoading()
		var create_rbType="公共费用";
		document.getElementById("create_RefeBursementType").value=create_rbType;
		var invoiceNum=document.getElementById("create_InvoiceNum").value;

		document.getElementById("create_Sum").value=document.getElementById("add_Sum").value;
		document.getElementById("create_Amount").value=document.getElementById("add_create_Amount").value;
		//createDetail();
		$('#createRBForm').submit();
	}

	function initCreateRBForm(){
		$("#createRBForm").form({
			url:'<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspCreateCommonReimbursement.jsp',
			onSubmit:function (){
			},
			success:function (data){
				if(data.indexOf("ERROR") != -1){
					$.messager.alert('错误',data,'error');
				}else{
					
					createDetail(data);
						window.location.href='<%=baseUrl %>shmged/jsp/com/shlcm/reimbursement/browseShowCommonReimbursement.jsp?oid='+data;
				}
			}
		});
	}

	function createDetail(oid)
	{

		var rows = $("#detailTable").datagrid('getRows');
		var infos="";
		for(var i=0; i<rows.length; i++){
			if(rows[i].desc==undefined){
				rows[i].desc=" ";
				}
			infos+=rows[i].type+"__"+rows[i].amount+"__"+rows[i].to+"__"+rows[i].time+"__"+rows[i].desc+"###";
		}
		var url="<%=baseUrl%>shmged/jsp/com/shlcm/reimbursement/jspCreateReimbursementDetail.jsp";
		var idata = {oid:oid,info:infos};
		  jQuery.post(url,idata,function (data){
	   	    	$.messager.alert('提示', data);
	        });
	}

	

	function browseCreateReimbursement(){
		  $('#browseCreateReimbursement').window({
			     collapsible:false,
			     minimizable:false,
			     maximizable:false,
			     resizable:false,
				 width:900,
			     height:640,
			     modal:true,
			     left:300,
			     top:10,
			     onClose:function(){
			  	 reLoadTab("费用报销");
			  	 $('#browseCreateReimbursement').window("destroy");
			     }
			 });
	}


	function closeCreateRB()
	{
		
		reLoadTab("费用报销");
		$('#browseCreateReimbursement').window('close');
		
	}
	

	/*添加附件功能*/
	function addDetailed(htmlId){
		//alert("appendixFileId :"+htmlId);
		var $div = $("#"+htmlId);
		var len = $div.children("input[type='file']") + 1;
		//alert("len :"+len);
		$div.append("<div><input type='file' size=60 name='appendixFile_"+len+"' /><input type='button' value='-' onclick='removeDetailed(this)'></input></div>");
	}
	function removeDetailed(obj){
		var temp = $(obj);
		temp.parent("div").remove(); 
	}

	function onClickRow(index)
	{
		editIndex=index;
	}
	
	function removeDetail(index)
	{

			$('#detailTable').datagrid('cancelEdit', editIndex)
			.datagrid('deleteRow', editIndex);
			setSum();
	}


	function setSum()
	{
		var rows = $("#detailTable").datagrid('getRows');
		var infos="";
		for(var i=0; i<rows.length; i++){
			infos=Number(infos)+Number(rows[i].amount);
		}
		document.getElementById("add_Sum").value=infos;
		document.getElementById("add_create_Amount").value=convertCurrency(infos);
	}
	
	initCreateRBForm();
</script>
</body>

</html>


